/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.demo.application.das;

import cn.hallele.demo.application.bo.PostBO;
import cn.hallele.ms.demo.domain.action.post.TypicodeDomainService;
import cn.hallele.ms.demo.domain.domain.PostDomain;
import cn.hallele.ms.infrastructure.core.convertor.das.ModelDas;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * TypicodeBO - TypicodeDomian转换器
 *
 * @author anle5
 * @since 2024/9/15 16:30
 */
@Slf4j
@Component
public class PostBDDas extends ModelDas<TypicodeDomainService, PostBO, PostDomain> {
    public PostBDDas(TypicodeDomainService option) {
        super(option);
    }

    public List<PostBO> querySomebodyPosts(int id) {
        return revertList(this.option.query(id));
    }

    /**
     * 将T转成E
     *
     * @param postBO 被转换者
     * @return E 转换后者
     */
    @Override
    protected PostDomain convert(PostBO postBO) {
        return PostDomain.builder()
                .id(postBO.getId())
                .userId(postBO.getUserId())
                .postId(postBO.getPostId())
                .title(postBO.getTitle())
                .body(postBO.getBody())
                .build();
    }

    /**
     * 将E回转陈T
     *
     * @param postDomain 被回转换者
     * @return E 回转换后者
     */
    @Override
    protected PostBO revert(PostDomain postDomain) {
        return PostBO.builder()
                .id(postDomain.getId())
                .userId(postDomain.getUserId())
                .postId(postDomain.getPostId())
                .title(postDomain.getTitle())
                .body(postDomain.getBody())
                .build();
    }
}
